{% extends 'CHOMPSGIBundle:Incidentes:base.html.twig' %}

{% block subtitle %}Nuevo{% endblock %}

{% set active_page = "incidentes_nuevo" %}
{% block content %}
	<script>
		$(document).ready(function(){
			$('#chomp_sgibundle_incidente_update_data').hide();
			$('#chomp_sgibundle_incidente_empresa').change(function(){
				$('#chomp_sgibundle_incidente_update_data').click();
			});
			$(document).keypress(function(e) {
				if(e.which == 13) {
					$('#chomp_sgibundle_incidente_update_data').click();
				}
			});


		});
	</script>
	<script>
		$(document).ready(function() {
			// Get the ul that holds the collection of tags
			var collectionHolder = $('#chomp_sgibundle_incidente_comentarios');

			// setup an "add a tag" link
			var $addComentarioLink = $('<a href="#" class="add_comentario_link">Agregar Comentario</a>');

			var $newLinkLi = $('<li></li>').append($addComentarioLink);
			
			// add the "add a tag" anchor and li to the tags ul
			collectionHolder.append($newLinkLi);

			// count the current form inputs we have (e.g. 2), use that as the new
			// index when inserting a new item (e.g. 2)
			collectionHolder.data('index', collectionHolder.find(':input').length);

			$addComentarioLink.on('click', function(e) {
				// prevent the link from creating a "#" on the URL
				e.preventDefault();

				// add a new tag form (see next code block)
				addComentarioForm(collectionHolder, $newLinkLi);
			});
		});
		
		function addComentarioForm(collectionHolder, $newLinkLi) {
			// Get the data-prototype explained earlier
			var prototype = collectionHolder.data('prototype');

			// get the new index
			var index = collectionHolder.data('index');

			// Replace '__name__' in the prototype's HTML to
			// instead be a number based on how many items we have
			var newForm1 = prototype.replace(/__name__label__/g, index);
			var newForm = newForm1.replace(/__name__/g, index);
			
			// increase the index with one for the next item
			collectionHolder.data('index', index + 1);

			// Display the form in the page in an li, before the "Add a tag" link li
			var $newFormLi = $('<li></li>').append(newForm);

			$newLinkLi.before($newFormLi);
		}
	</script>
	
	<h1>Incidente con ID </h1>

	{{ form_start(form, {attr: {novalidate: 'novalidate'}}) }}

	<table>
	  <tr>
	    <td>ID:</td>
	    <td>{{incidente.getId()}}</td>
	  </tr>
	  <tr>
	    <td>Fecha Creación:</td>
	    <td>{{incidente.getFechaCreacion().format('d-m-Y H:i:s') | default("") }}</td>
	  </tr>
	  <tr>
	    <td>Fecha Modificación:</td>
	    <td>{{incidente.getFechaModificacion().format('d-m-Y H:i:s') | default("") }}</td>
	  </tr>
	  <tr>
	    <td>Fecha Limite SLA:</td>
	    <td>{{incidente.getFechaLimiteSLA().format('d-m-Y H:i:s') | default("") }}</td>
	  </tr>
	  <tr>
	    <td>Fecha Cierre Automático:</td>
	    <td>{{incidente.getFechaCierreAutomatico().format('d-m-Y H:i:s') | default("") }}</td>
	  </tr>
	  <tr>
	    <td>Fecha Cierre:</td>
	    <td>{{incidente.getFechaCierre().format('d-m-Y H:i:s') | default("") }}</td>
	  </tr>
	</table>
	
	<table>
	  <tr>
	    <td>{{ form_label(form.titulo) }}</td>
	    <td>{{ form_errors(form.titulo) }} {{ form_widget(form.titulo) }}</td>
	  </tr>
	  <tr>
	    <td>{{ form_label(form.estado) }}</td>
	    <td>{{ form_errors(form.estado) }} {{ form_widget(form.estado) }}</td>
	  </tr>
	  <tr>
	    <td>{{ form_label(form.prioridad) }}</td>
	    <td>{{ form_errors(form.prioridad) }} {{ form_widget(form.prioridad) }}</td>
	  </tr>
	  <tr>
	    <td>{{ form_label(form.empresa) }}</td>
	    <td>{{ form_errors(form.empresa) }} {{ form_widget(form.empresa) }}</td>
	  </tr>
	  <tr>
	    <td>{{ form_label(form.cuentaAnalitica) }}</td>
	    <td>{{ form_errors(form.cuentaAnalitica) }} {{ form_widget(form.cuentaAnalitica) }}</td>
	  </tr>
	  <tr>
	    <td>{{ form_widget(form.save) }}</td>
		<td>{{ form_widget(form.update_data) }}</td>
	  </tr>
	</table>

	{{ form_row(form.comentarios) }}
	
	{{ form_end(form) }}
{% endblock %}
